﻿@using EC.Entity.Enum;
@{
    Layout = "~/Views/Shared/_Dialog.cshtml";
}
@section HeadCss{
    <link href="@Url.Content("~/lib/select2/select2.min.css")" rel="stylesheet" />
}
@section headScripts{
    <script type="text/javascript" src="@Url.Content("~/lib/select2/select2.min.js")"></script>
}
@model EC.Entity.Response.Merchant.MerchantResponse
<section class="container-fluid" style="background-color: white;">
    <form class="form-horizontal m15_t" id="form">
        <div class="tab-content">
            <input type="hidden" id="MerchantId" name="MerchantId" value="@(Model.Id)">
            <div class="tab-pane fade in active" id="home">
                <div class="form-group">
                    <label class="wd100 control-label">商户：</label>
                    <div class="wd350">
                        <select name="proxyId" class="wd350 js-example-basic-multiple" multiple="multiple">
                            @{

                                var mailContentResponses = (List<EC.Entity.Response.Merchant.MerchantResponse>)Model.noMerchantResponse;
                                if (mailContentResponses != null && mailContentResponses.Any())
                                {
                                    foreach (var item in mailContentResponses)
                                    {
                                        if (Model.yesMerchantResponse != null && Model.yesMerchantResponse.Any())
                                        {
                                            if (Model.yesMerchantResponse.Any(c => c.Id == item.Id))
                                            {
                                                <option value="@(item.Id)" selected>@(item.Name)</option>
                                            }
                                            else
                                            {
                                                <option value="@(item.Id)">@(item.Name)</option>
                                            }
                                        }
                                        else
                                        {
                                            <option value="@(item.Id)">@(item.Name)</option>
                                        }
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
@section footerScript{
    <script type="text/javascript">
        var proxyId = $("select[name='proxyId']");

        $(function () {
            proxyId.select2({
                placeholder: '选择商户'
            });
        });
        function save() {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            var data = $("#form").serializeObject();
            //状态
            //data.status = $("input[name='status'][checked]").val();

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Merchant/SaveProxy",
                data: data,
                success: function (res) {
                    if (res.success) {
                        cover.Remove();
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        cover.Remove();
                        FlashPay.UI.Tip_short_warning("操作失败！" + res.message);
                    }
                },
                error: function (json) {
                    cover.Remove();
                    FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                }
            });

        }

        $.fn.serializeObject = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };
    </script>
}